<template>
  <div class="mt-form-item">
    <slot></slot>
  </div>
</template>


<script>
  const formEmitterBehavior = require('../../static/emitter.behavior')
  const formItemBehavior = require('../../static/form-item.behavior')
  const formELementBehavior = require('../../static/form-element.behavior')

  function noop() {}

  export default {
    behaviors: [
      formEmitterBehavior,
      formItemBehavior,
      formELementBehavior
    ],
    relations: {
      '../mt-form/index': {
        type: 'ancestor', // 关联的目标节点应为祖先节点
        linked(v) {
          this.form = v
          // console.log('this.form', this.form)
        },
        unlinked() {
          this.form = null
        }
      },
      formELementBehavior: {
        type: 'descendant', // 关联的目标节点应为子孙节点,
        target: formELementBehavior,
        linked: function (formElement) {
          this.formELements[formElement.$id] = formElement
          // console.log('this.formELements', this.formELements)
        },
        unlinked: function (formElement) {
          delete this.formELements[formElement.$id]
        }
      }
    },
    properties: {
      prop: {
        type: [String],
        value: ''
      }
    },
    data() {
      return {}
    },
    attached() {
      this.form = null
      this.formELements = {}
    },
    methods: {
      validate(trigger, callback = noop) {

      },
      clearValidate() {

      },
      getRules() {

      },
      setValue(v) {
        // this.setData({
        //   value: v
        // })
      },
      mtFormChange(val) {
        // console.log('val', val)
        this.setValue(val)
        this.callComponent(this.form, 'mtFormChange', [this.data.prop, val])
        this.validate('change')
      }
    }
  }
</script>
